<template>
    <div class="box">
        <el-row :gutter="20" v-permission="['getStatistics1,GET']">
            <template v-if="panels.length == 0">
                <el-col :span="6" v-for="i in 4" :key="i">
                    <el-skeleton style="width: 100%" animated loading>
                        <template #template>

                            <el-card class="border-0" shadow="hover">
                                <template #header>
                                    <div class="flex justify-between">
                                        <el-skeleton-item variant="text" style="width: 50%" />
                                        <el-skeleton-item variant="text" style="width: 10%" />
                                    </div>
                                </template>
                                <el-skeleton-item variant="h3" style="width: 80%" />
                                <el-divider />
                                <div class="flex justify-between text-sm text-gray-500">
                                    <el-skeleton-item variant="text" style="width: 50%" />
                                    <el-skeleton-item variant="text" style="width: 10%" />
                                </div>
                            </el-card>





                        </template>
                    </el-skeleton></el-col>
            </template>

            <el-col v-else :span="6" :offset="0" v-for="(item, index) in panels " :key="index">
                <el-card class="border-0" shadow="hover">
                    <template #header>
                        <div class="flex justify-between">
                            <span class="text-sm"> {{ item.title }}</span>
                            <el-tag :key="item.label" :type="item.unitColor" effect="plain">
                                {{ item.unit }}
                            </el-tag>
                        </div>
                    </template>
                    <span class="text-3xl font-bold text-gray-500">
                    <CountTo :value="item.value"/></span>
                    <el-divider />
                    <div class="flex justify-between text-sm text-gray-500">
                        <span>{{ item.subTitle }}</span>
                        <span>{{ item.subValue }}</span>
                    </div>
                </el-card>

            </el-col>

        </el-row>
        <homeNav/>
        <el-row :gutter="20"  class="mt-5">
            <el-col :span="12" :offset="0">
                <!-- v-permission="['getStatistics3,GET']" -->
                <homeChart v-permission="['getStatistics3,GET']"/>
            </el-col>
            <el-col :span="12" :offset="0" v-permission="['getStatistics2,GET']">
            <homeCard title="店铺及商品提示" tip="店铺及商品提示" :list="goods" class="mb-3"/>
            <homeCard title="交易提示" tip="需要立即处理的交易订单" :list="order"/>
            </el-col>
            

        </el-row>
    </div>
</template>
<script setup>
import { ref } from 'vue';
import { getStatistics1,getStatistics2 } from '@/api/home.js'
import CountTo from '@/components/CountTo.vue';
import homeNav from '../components/homeNav.vue';
import homeChart from '../components/homeChart.vue';
import homeCard from '../components/homeCard.vue';
const panels = ref([])
const goods = ref([])
const order = ref([])
getStatistics1().then(
    res => {
        // 已拿到
        // console.log(res);
        panels.value = res.panels
        // 已赋值成功
        // console.log(panels.value);
    }
)
getStatistics2().then(
    res => {
        // 已拿到
        console.log(res);
         // 已赋值成功
         goods.value=res.goods
         order.value=res.order
        //  console.log(goods.value);

    
    }
)


</script>
<style lang="scss" scoped>
.title {}
</style>